﻿using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Bildschirmpause {
    /// <summary>
    /// Interaction logic for SettingsWindow.xaml
    /// </summary>
    public partial class SettingsWindow : Window {
        public ConfigOptions currentConfigOptions = new ConfigOptions();
        public SettingsWindow() {
            InitializeComponent();
            this.DataContext = currentConfigOptions;
            currentConfigOptions.PropertyChanged += currentConfigOptions_PropertyChanged;
        }

        void currentConfigOptions_PropertyChanged(object sender, PropertyChangedEventArgs e) {
            if (currentConfigOptions.BreakTimeBase == 10 && currentConfigOptions.WorkTimeBase == 50)
                IntervalComboBox.SelectedIndex = 1;
            else if (currentConfigOptions.BreakTimeBase == 20 && currentConfigOptions.WorkTimeBase == 100)
                IntervalComboBox.SelectedIndex = 2;
            else IntervalComboBox.SelectedIndex = 0;
        }

        private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void Button_Click(object sender, RoutedEventArgs e) {
            this.DialogResult = true;
        	this.Close();
        }

        public class ConfigOptions : INotifyPropertyChanged {
            private double workTimeBase;
            private double breakTimeBase;

            public double WorkTimeBase {
                get {
                    return this.workTimeBase;
                }
                set {
                    this.workTimeBase = value;
                    OnPropertyChanged("WorkTimeBase");
                }
            }

            public double BreakTimeBase {
                get {
                    return this.breakTimeBase;
                }
                set {
                    this.breakTimeBase = value;
                    OnPropertyChanged("BreakTimeBase");
                }
            }

            public event PropertyChangedEventHandler PropertyChanged;

            private void OnPropertyChanged(string propertyName) {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void IntervalComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
            var thisComboBox = sender as ComboBox;
            if (thisComboBox.SelectedIndex == 1) {
                currentConfigOptions.BreakTimeBase = 10;
                currentConfigOptions.WorkTimeBase = 50;
            } else if (thisComboBox.SelectedIndex == 2) {
                currentConfigOptions.BreakTimeBase = 20;
                currentConfigOptions.WorkTimeBase = 100;
            }
        }
    }
}
